import 'package:flutter/material.dart';
import 'package:flutter_xyf/pages/extend/file_upload/FileUpload.dart';
import 'package:flutter_xyf/pages/index/index.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'pages/component/index.dart';
import 'pages/extend/canvas_example/CanvasExample.dart';
import 'pages/extend/keyboard_example/KeyboardExample.dart';
import 'pages/extend/listen_example/ListenExample.dart';

// import './ceshi/index.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

//通过 navigatorKey.currentState.overlay.context 获取全局context。
GlobalKey<NavigatorState> _navigatorKey = GlobalKey();

// 可以实现无 context 调用 snack bars
GlobalKey<ScaffoldMessengerState> _scaffoldKey = GlobalKey();
// _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("show SnackBar")));

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: _navigatorKey,
      scaffoldMessengerKey: _scaffoldKey,
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.orange, primaryColor: Colors.red),
      // home: FileUploadPage(),
      // initialRoute: '/cehsi',
      // home: HomePage(),
      // home: CanvasExample(),
      home: KeyboardExample(),

      // onGenerateRoute: (setting) {
      //   // 当找不到route的时候会走这里
      //   print(setting.name);
      //   print(setting.arguments);
      //   return MaterialPageRoute(builder: (_) => HomePage());
      // },

      //当构建 Widget 前调用，主要用于字体大小、主题颜色等配置
      // builder: (_, child) {
      //   return Scaffold(
      //     appBar: AppBar(title: Text("build")),
      //     body: child,
      //   );
      // },
      navigatorObservers: [MyObserver()],
      // showSemanticsDebugger: true, //打开显示可访问性信息的叠加层，展示组件之间的关系、占位大小
      debugShowCheckedModeBanner: false, //调试显示检查模式横幅

      locale: Locale('zh', 'CN'), // 中文简体
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
    );
  }
}

class MyObserver extends NavigatorObserver {
  @override
  void didPush(Route route, Route? previousRoute) async {
    // print(route);
    // print(previousRoute);
    super.didPush(route, previousRoute);
  }
}
